#include <stdio.h>

int main()
{
	int m,f,ty,ys,xb;
	double g;
	scanf("%c %d %d %c %c", &xb, &f, &m, &ty, &ys);
	if ('M' == xb){
		g = (f+m)*0.54;
	}else if ('F' == xb){
		g = (f*0.923 + m)/2;
	}
	if ('Y' == ty){
		g *= 1.02;
	}
	if ('Y' == ys){
		g *= 1.015;
	}
	printf("%f", g);
	return 0;
} 
